package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.UserDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao ;
//用户登录验证
    @Override
    public User findByUsername(String username) {
        return userDao.findWithRolesByUsername(username);
    }
//增加用户
    @Override
    public void add(User user) {
        userDao.add(user);
    }
//分页查询
@Override
public PageResult findPage(QueryPageBean  pageBean) {
    Integer currentPage = pageBean.getCurrentPage();
    Integer pageSize = pageBean.getPageSize();
    String queryString = pageBean.getQueryString();
    //使用分页助手插件实现分页查询
    PageHelper.startPage(currentPage,pageSize);
    Page<User> page = userDao.findByCondition(queryString);
    return new PageResult(page.getTotal(),page.getResult());
}
//查询角色数据
/*
@Override
public List<User> findAll() {
    return userDao.findAll();
}
*/


//删除用户
    @Override
    public void deleteById(Integer id) {
      /*  //判断该检查项是否被引用
        int count = userDao.selectCheckItemReferencedCount(id);

        if(count>0){
            throw new RuntimeException("当前检查项被引用，不能删除 !");
        }*/
        userDao.deleteById(id);
    }
}
